/*
 * Copyright (C) 2008 Jens Meiß
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.blog;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.text.ITextblockWithTitle;


/**
 * 
 * 
 * @author jens.meiss
 */
@Entity
@NamedQueries({
	@NamedQuery(name="BlogEntry.findByBlog", query="SELECT blogEntry FROM BlogEntry blogEntry WHERE blogEntry.blog = ?1")
})
public class BlogEntry implements ITextblockWithTitle {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * contains the related blog
	 */
	private Blog blog;

	/**
	 * date of the blog entry
	 */
	private Date date;

	/**
	 * contains the ID of the blog entry
	 */	
	private int id;

	/**
	 * contains all BlogComments of the Blog
	 */
	private List<BlogEntryComment> blogComment;
	
	/**
	 * text of the blog entry
	 */
	private String text;

	/**
	 * the title of the blog entry
	 */
	private String title;
	
	@ManyToOne(optional=false, cascade=CascadeType.PERSIST)
	public Blog getBlog() {
		return blog;
	}

	/**
	 * @return the date
	 */
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDate() {
		return date;
	}

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, mappedBy="blogEntry")
	public List<BlogEntryComment> getBlogComment() {
		return blogComment;
	}

	/**
	 * @return the text
	 */
	@Column(length=10000, nullable=false)
	public String getText() {
		return text;
	}

	/**
	 * @return the title
	 */
	@Column(nullable=false)
	public String getTitle() {
		return title;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	public void setBlogComment(List<BlogEntryComment> blogComment) {
		this.blogComment = blogComment;
	}

	/**
	 * @param text
	 *            the text to set
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
}
